package com.netty.esc.common.exception;

import com.netty.esc.common.base.BaseResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: zhaoyang05
 * @Data: 2022/3/23 15:55
 * @Description
 */
@RestControllerAdvice
@Slf4j
public class AllExceptionController {

//    @ExceptionHandler(value = MethodArgumentNotValidException.class)
//    public BaseResponseDTO AllException(MethodArgumentNotValidException ex){
//        FieldError fieldError = ex.getBindingResult().getFieldError();
//        if (fieldError!=null) {
//            return BaseResponseDTO.setResultError(fieldError.getDefaultMessage());
//        }
//        return BaseResponseDTO.setResultError("异常");
//    }

    @ExceptionHandler(value = Exception.class)
    public BaseResponseDTO<Object> AllException(Exception ex){
        log.error("服务器异常",ex);
        return BaseResponseDTO.setResultError(ex.getMessage());
    }

}
